package com.dk.service.impl;

import com.dk.Vo.TBookVo;
import com.dk.mapper.TBookMapper;
import com.dk.pojo.TBook;
import com.dk.service.TBookServiceI;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TBookServiceImpl implements TBookServiceI {

    @Autowired
    private TBookMapper tBookMapper;

    @Override
    public PageInfo<TBookVo> getInfoServer(Integer pageNum, Integer pageSize,String bookName,Integer publisher,Integer author,Integer bookCategory) {
        PageHelper.startPage(pageNum,pageSize);
        List<TBookVo> list = tBookMapper.getInfoServer(bookName,publisher,author,bookCategory);
        PageInfo<TBookVo> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public void addById(TBook tBook) {
        tBook.setBookState(1);
        tBookMapper.insertSelective(tBook);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        tBookMapper.deleteBatch(ids);
    }

    @Override
    public TBook getUpdateInfo(Integer bookId) {
        return tBookMapper.selectByPrimaryKey(bookId);
    }

    @Override
    public void updateById(TBook tBook) {
        tBookMapper.updateByPrimaryKeySelective(tBook);
    }

    @Override
    public PageInfo<TBookVo> getInfoServers(Integer pageNum, Integer pageSize, String bookName, Integer publisher, Integer author, Integer bookCategory) {
        PageHelper.startPage(pageNum,pageSize);
        List<TBookVo> list = tBookMapper.getInfoServers(bookName,publisher,author,bookCategory);
        PageInfo<TBookVo> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public TBook getUpdateInfos(Integer bookId) {
        return tBookMapper.selectByPrimaryKey(bookId);
    }

    @Override
    public void updateState(TBook tBook) {
        tBookMapper.updateByPrimaryKeySelective(tBook);
    }
}
